package com.mfc.education.service.edu.service.impl;

import com.mfc.education.service.edu.entity.CourseCollect;
import com.mfc.education.service.edu.entity.vo.CourseCollectVo;
import com.mfc.education.service.edu.mapper.CourseCollectMapper;
import com.mfc.education.service.edu.service.CourseCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程收藏 服务实现类
 * </p>
 *
 * @author Mfc
 * @since 2021-07-25
 */
@Service
public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectMapper, CourseCollect> implements CourseCollectService {

    @Override
    public boolean saveCollect(String courseId, String memberId) {
        //判断是否已收藏
        boolean result = selectCollect(courseId, memberId);
        if (result) return true;

        CourseCollect courseCollect = new CourseCollect();
        courseCollect.setCourseId(courseId);
        courseCollect.setMemberId(memberId);

        return this.save(courseCollect);
    }

    @Override
    public boolean removeCourseCollect(String courseId, String memberId) {
        if (!selectCollect(courseId, memberId)) return true;
        Integer result = baseMapper.removeCourseCollect(courseId, memberId);
        if (result != null && result.intValue() > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<CourseCollectVo> courseCollectListMy(String memberId) {
        return baseMapper.courseCollectListMy(memberId);
    }

    @Override
    public boolean selectCollect(String courseId, String memberId) {


        Integer count = baseMapper.selectCollect(courseId,memberId);

        if (count != null && count.intValue() > 0){
            return true;
        }

        return false;
    }
}
